def rc_decode(rc):
    count = 0
    deposit = 0
    end=""
    number =""
    normalID=""
    if rc[0] == "R":
        for i in rc:
            if i == "C":
                count = count + 1
        if count == 1:
            i=rc.split("C")
            length=len(rc)
            num=length
            for i in range(length):
                num-=1
                if rc[length-i-1]=="C":
                    break
                else:
                    end=rc[length-i-1]
                    number=end+number
            number=int(number)
            while(number>26):
                if number>26:
                    deposit=number%26
                    if deposit==0:
                        deposit=26
                    normalID=chr(deposit+64)+normalID
                    number=int((number-deposit)/26)
                    #返回值       
            if number<=26:
                normalID=chr(number+64)+normalID       
                normalID=normalID+rc[1:num]
                """
                            if normalID[0]>="Z" or normalID[0]<="A":
                normalID="格式错误"
                """
        else:
            normalID="格式错误"
    else:
        normalID="格式错误"
    return normalID    
    

if __name__ == '__main__':
    write=input("输入需要运算的次数:")
    write=int(write)
    while(write>0):
        write-=1
        change=input("输入需要更改的RCID:")
        print(rc_decode(change))